Repository navigation
solver: an emitted transaction's fee goes to the execution whose new_state precedes it in the block - #94
Merged
Conversation
…ract Dice reads its own balance and pays 10 CS when it holds at least 20: a node re-executing it while it syncs sees the balance after the same block's payout, throws, keeps a stale state and charges a later payout's fee to the previous player. contracts.py --dice (run.sh CONTRACT_DICE=1) deploys it, funds it, and has two players play it three times in turn before the restart test; its state is compared on every node. Scenario contracts-dice-join (manual): a node syncs from block 0 through the plays. It is expected to fail until contract states are fetched instead of re-executed (step 0 of the contract state sync plan). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…state precedes it in the block A node that syncs re-executes contract calls to rebuild their states; for a contract whose result depends on its own balance the re-execution is not reproducible, the state stays stale and the contract's last known execution is an earlier one: the fee of a later payout was charged to the previous initiator, and the node's balances differed from the live nodes', which have the new state before the block. The fee now goes to the initiator of the contract's nearest new_state before the emitted transaction in the same block, the rule the rollback already applies (now through the same helper, which also bounds its search to the block); the last known execution only when the block has no new_state. Consensus-relevant: a syncing node's balances change by one fee per affected payout compared with an official node that syncs the same blocks, and agree with the nodes that executed the contract. Step 1 of the contract state sync plan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed-fee-attribution
…sful execution in the block Review of step 1: a live node applies every new_state of the block (Conveyer::statesCreated -> on_update) before it charges any emitted transaction, so with several executions of one contract in a block it charges all their payouts to the latest successful one, not to the execution that precedes each payout. The helper now returns the highest RefStart among the contract's new_states with a non-zero hash, wherever the emitted transaction stands; the rollback uses the same rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 1 of the contract state sync plan (docs/specs/2026-10-24-contract-state-sync-design.md on docs/contract-state-sync). Consensus-relevant, approved by the user ("the rule of the live nodes").
Problem. A syncing node re-executes contract calls to rebuild their states, because blocks carry only the state hash. For a contract whose result depends on its own balance (dice games), the re-execution is not reproducible. The state stays stale, and the fee of a later payout was charged to the contract's last known execution, i.e. the previous player. This is how the local mainnet node came to differ by one fee on wallet 7hWM… (block 176,776,317); mainnet nodes disagree among themselves on such wallets.
Change.
SmartContracts::emitting_new_state(block, index, contract)returns the RefStart of the contract's nearest new_state before the emitted transaction in the same block. The fee goes to that execution's initiator: the rule the live nodes follow, since they have the state before the block, and the oneon_remove_blockalready applies to refunds.on_remove_blocknow uses the same helper, so the two cannot drift, and its search no longer runs past the start of the block when no new_state precedes. The last known execution remains the fallback when the block has none, with a warning.Effect. A syncing node's balances change by one fee per affected payout compared with an official node that syncs the same blocks, and agree with the nodes that executed the contract. The contract's own state is still stale after a failed re-execution; that is steps 2–3.
Tests. A unit test of the helper. Contains #93 (step 0, the dice scenario):
contracts-dice-joinmust now show identicalSTATE DIGESTs on every node, n8 included. The Dice state is still expected to differ.🤖 Generated with Claude Code